package com.itheima.refect;

import com.itheima.domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/*
获取方法
并 调用方法

 */
public class Demo05 {

    public static void main(String[] args) throws Exception {
        Class<Student> clazz = (Class<Student>) Class.forName("com.itheima.domain.Student");
        //创建对象
        Constructor<Student> constructor = clazz.getDeclaredConstructor();
        constructor.setAccessible(true);
        Student student = constructor.newInstance();



        Method sing = clazz.getMethod("sing");
        System.out.println(sing);
        sing.invoke(student);

        Method dance = clazz.getMethod("dance",String.class);
        System.out.println(dance);
        dance.invoke(student,"我是参数");
        Method play = clazz.getMethod("playbasketball",String.class,int.class);
        System.out.println(play);
        Object string = play.invoke(student, "String", 18);
        System.out.println(
                "接收到了返回值"+string
        );
        Method study = clazz.getDeclaredMethod("study", String.class);
        System.out.println(study);
        study.setAccessible(true);
        Object ooo = study.invoke(student, "我是study的参数");
        System.out.println(ooo);
    }
}
